package edu.lsnu.equipment_management_system.service.impl;

import edu.lsnu.equipment_management_system.mapper.update.ChangePasswordMapper;
import edu.lsnu.equipment_management_system.pojo.vo.sql_conditions.PasswordAndUserNoVo;
import edu.lsnu.equipment_management_system.service.ChangePasswordService;
import edu.lsnu.equipment_management_system.util.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author mzy
 * @Description
 * @date 2018/11/25
 */
@Service
@Transactional(propagation= Propagation.REQUIRED)
public class ChangePasswordServiceImpl implements ChangePasswordService {
    @Autowired
    ChangePasswordMapper mapper;

    @Override
    public boolean changePassword(String password, String userNo) {
        // md5加密
        // password = MD5Util.md5(password);
        password = MD5Util.changePass(password);
        // 封装password和userNo对象
        PasswordAndUserNoVo passwordAndUserNoVo = new PasswordAndUserNoVo();
        passwordAndUserNoVo.setPassword(password);
        passwordAndUserNoVo.setUserNo(userNo);
        // 修改密码
        int count = mapper.changePassword(passwordAndUserNoVo);
        if (0 == count) {
            return false;
        }
        return true;
    }
}
